<?php


namespace app\controller;


use app\BaseController;
use think\facade\Db;
use think\facade\Request;

class Comment extends BaseController
{
    /**
     * 点赞
     */
    public function give(){
        $_data['friends_id']=Request::param('friends_id');
        $_data['user_id']=Request::param('user_id');
        $result=Db::name('give')->where($_data)->find();
        if($result){
            $status=$result['status']==0?1:0;
            Db::name('give')->where('id',$result['id'])->update(['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);
            return json(['code'=>'0','msg'=>'点赞成功']);
        }
        $_data['create_time']=date('Y-m-d H:i:s');
        $_data['status']=0;
        if(Db::name('give')->insert($_data)){
            return json(['code'=>0,'msg'=>'点赞成功']);
        }
        return json(['code'=>1,'msg'=>'失败']);
    }
    /**
     * 评论
     */
    public function send(){
        $_data['friends_id']=Request::param('friends_id');
        $_data['user_id']=Request::param('user_id');
        $_data['content']=Request::param('content');
        $_data['status']=0;
        $_data['create_time']=date('Y-m-d H:i:s');
        if(Db::name('comments')->insert($_data)){
            return json(['code'=>0,'msg'=>'评论完成']);
        }
        return json(['code'=>1,'msg'=>'评论失败']);
    }
}